﻿using System.Windows.Media.Imaging;
using Autodesk.Revit.UI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using RevitCopilot.MCPServer;
using RevitCopilot.Extensions;
using Tuna.Revit.Extension;

namespace RevitCopilot;

public class Application : IExternalApplication
{
    public Result OnStartup(UIControlledApplication application)
    {   
        //创建UI面板，添加按钮
        this.CreateRibbon(application);
        Host.Start();
        var logger = Host.GetService<ILogger<Application>>();
        logger.LogInformation("RevitCopilot插件启动");
        return Result.Succeeded;
    }
    public Result OnShutdown(UIControlledApplication application)
    {
        var logger = Host.GetService<ILogger<Application>>();
        logger.LogInformation("RevitCopilot插件关闭");
        Host.Stop();
        return Result.Succeeded;
    }
    private void CreateRibbon(UIControlledApplication application)
    {
        var tab = application.AddRibbonTab("RevitCopilot");
        tab.AddRibbonPanel("服务", panel =>
        {
            panel.AddPushButton<StartupCommand>(button =>
                {
                    button.LargeImage = new BitmapImage(
                        new Uri("pack://application:,,,/RevitCopilot;component/Resources/Icons/start.png"));
                    button.ToolTip = "开启MCP服务";
                    button.Title = "开启";
                }
                ).AddPushButton<SettingCommand>(button =>
                {
                    button.LargeImage = new BitmapImage(
                        new Uri("pack://application:,,,/RevitCopilot;component/Resources/Icons/setting.png"));
                    button.ToolTip = "设置MCP服务";
                    button.Title = "设置";
                });
        });
    }
}